package com.epoint.mobileoa.bizlogic.mobileoa;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.dom4j.Element;

import android.os.Message;

import com.epoint.mobileoa.bizlogic.SuperView;
import com.epoint.mobileoa.bizlogic.Task;
import com.epoint.mobileoa.datanalysis.XMLHelp;
import com.epoint.mobileoa.http.HttpHelp;
import com.epoint.mobileoa.model.MailList;

/**
 * @author liyc
 * @time 2012-2-22 上午2:01:13
 * @annotation 
 */
public class GetMailListTask extends Task {

	/**
	 * @param con
	 * @param param
	 */
	public GetMailListTask(SuperView con, HashMap<String, Object> param) {
		super(con, param);
		
	}

	@Override
	public void exectue(Message mess) throws Exception {
		Integer pagenum = (Integer) getParam().get("pagenum");
		Integer shownum = (Integer) getParam().get("shownum");
		
		String sjfrom = getParam().get("sjfrom")==null?"":(String)getParam().get("sjfrom");
		String sjto = getParam().get("sjto")==null?"":(String)getParam().get("sjto");
		String bt = getParam().get("bt")==null?"":(String)getParam().get("bt");
		String sjr = getParam().get("sjr")==null?"":(String)getParam().get("sjr");
		
//		String seamurl = generateURL("getMailList",getFP().getUserguid(),pagenum+"",shownum+"",sjfrom,sjto,bt,sjr);
		
		String seamurl = getCon().fp.getSeamurl()+"?requestType=getMailList&userguid="+getCon().fp.getUserguid()+"&pagenum="+pagenum+"&shownum="+shownum+
				"&param4="+sjfrom+"&param5="+sjto+"&param6="+bt+"&param7="+sjr;
		System.out.println(seamurl);
		String bs = HttpHelp.getHttpBack(seamurl);
		
		setMessageToRefreshUI(mess, getCon(), bs);
	}
	
	public static List<MailList> XmlAnalysis(String xml){
		List focs = XMLHelp.getRoot(xml).elements();
		List<MailList> mailList = new ArrayList<MailList>();
		for (int i = 0; i < focs.size(); i++) {
			MailList emaillist = new MailList();
			Element foc = (Element) focs.get(i);
			if (foc.element("guid") != null)
				emaillist.guid = foc.elementText("guid");
			if (foc.element("title") != null)
				emaillist.title = foc.elementText("title");
			if (foc.element("msgFrom") != null)
				emaillist.msgFrom = foc.elementText("msgFrom");
			if (foc.element("time") != null)
				emaillist.time = foc.elementText("time");
			if (foc.element("status") != null)
				emaillist.status = foc.elementText("status");
			if (foc.element("attachment") != null)
				emaillist.attachment = foc.elementText("attachment");
			mailList.add(emaillist);
		}
		return mailList;
	}

}
